#pragma once

#include "LodePng.h"

#include <QDebug>

// C headers
#include <stdlib.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>

// C++ headers
#include <map>
#include <vector>
#include <array>

// SFF
typedef struct {
    uint8_t Ver3, Ver2, Ver1, Ver0;
    uint32_t FirstSpriteHeaderOffset;
    uint32_t FirstPaletteHeaderOffset;
    uint32_t NumberOfSprites;
    uint32_t NumberOfPalettes;
} SffHeader;

struct Color {
    uint8_t R = 0;
    uint8_t G = 0;
    uint8_t B = 0;
    uint8_t A = 0;
};

struct Palette {
    Color ColorArray[256];
};

struct Sprite {
    uint16_t Group;
    uint16_t Number;
    uint16_t W;
    uint16_t H;
    int16_t OX;
    int16_t OY;
    int PalIdx;
    int Rle;
    uint8_t ColDepth;
    std::vector<Color> ColorList;

    // Constructor!
    Sprite() {
        Group = 0;
        Number = 0;
        W = 0;
        H = 0;
        OX = 0;
        OY = 0;
        PalIdx = 0;
        Rle = 0;
        ColDepth = 0;
    }
};

typedef struct {
    char Filename[256];
    SffHeader Header;
    std::vector<Sprite> Sprites;
    std::vector<Palette> Palettes;
    std::map<int, int> PaletteUsage;
    std::map<int, int> CompressionFormatUsage;
    size_t NumLinkedSprites;
} Sff;

int LoadMugenSffFile(const char* filename, Sff *sff);
